#ifndef CmdReadH
#define CmdReadH
#include "Command.h"

class CmdRead : public Command
{
public:
	CmdRead(II2CRW *i2crw, VarMap *vmp, const std::string& cmd) : Command(i2crw, vmp, cmd) {}

	virtual int execute() override 
	{
		//m_i2crw->ReadArray();
		return 0;
	}

protected:
	virtual bool pickUp() override 
	{
		switch (m_argc)
		{
		case 2: // read devaddr subaddr? readLen?
		{
			m_DevAddr = m_argv[1];
			m_SubAddr = "0x00";
			m_ReadLen = "1";
			break;
		}
		case 3: // read devaddr subaddr readLen?
		{
			m_DevAddr = m_argv[1];
			m_SubAddr = m_argv[2];
			m_ReadLen = "1";
			break;
		}
		case 4: // read devaddr subaddr readLen
		{
			m_DevAddr = m_argv[1];
			m_SubAddr = m_argv[2];
			m_ReadLen = m_argv[3];
			break;
		}
		default:
			return false;
		}
	}

	virtual bool checkUp() override
	{
		if (!isValidI2CAddr(m_DevAddr)) 
		{
			return false;
		}

		if (!isValidI2CAddr(m_SubAddr))
		{
			return false;
		}

		if (!isValidReadLength(m_ReadLen))
		{
			return false;
		}
	}
private:
	std::string m_DevAddr;
	std::string m_SubAddr;
	std::string m_ReadLen;
};


#endif // !CmdReadH

